var vue = new Vue({
	
	el : '#good_location_main',
	data : {
		currentPage : 1,
		pageSize : 5,
		totalSize : 100,
		tableData: [],
		queryBtn : false,
		goodsLocation : {
			id :　'',
			locationName : '',
			locationDesc : ''
		},
		
		goodsAndLocation : {
			
			id : '',
			goodsId : '',
			locationId : '',
			goodsNum : ''
			
		},
		locations : [],
		wareHouseVO2 : {
			id : '',
			entryDate : '',
			updateDate : '',
			houseId : '',
			houseName : '',
			positionId : '',
			positionName : '',
			goodsBarCode : '',
			goodsName : '',
			goodsDesc : '',
			goodsUnit : '',
			goodsPrice : '',
			goodsNum : '',
			sku : '',
			goodsType : '',
			locationId : '',
			locationName : '',
			warningValue : ''
		}
	},
	mounted(){
		this.initGoodLocation();
	},
	methods : {
		editForm(row){
			this.wareHouseVO2 = row;
		},
		changeLocationValue(val){
			let obj = {};
			obj = this.locations.find((item)=>{
				return item.id === val;
			});
			this.wareHouseVO2.locationName = obj.locationName;
		},
		updateForm(form,row){
			$.ajax({
				url : COMMON_URL.URL + 'goodsLocationController/updateGoodsTrade',
				type : 'post',
				contentType : 'application/json',
				data : JSON.stringify(row),
				success : function(data){
					if(data.ok){
						vue.closePopper();
					}else{
						swal('更新失败:'+data.msg,'','warning');
					}
				},
				error : function(data){
					swal('更新失败','','error');
				}
				
			});
		},
		closePopper(loId){
			$('#user_controller_btn').trigger('click');
			this.onQuery(this.currentPage,this.pageSize);
		},
		handleCurrentChange(val){
			this.currentPage = val;
			vue.onQuery(val,this.pageSize);
		},
		handleSizeChange(val){
			this.pageSize = val;
			vue.onQuery(this.currentPage,val);
		},
		onQuery(pageNum,pageSize){
			var locationId = this.goodsLocation.id;
			
			if(locationId == null || locationId == ''){
				return;
			}
			
			$.ajax({
				
				url : COMMON_URL.URL + 'goodsLocationController/showLocationsGoods',
				dataType : 'json',
				type : 'get',
				data : {
					'locationId' : locationId,
					'pageNum' : pageNum,
					'pageSize' : pageSize
				},
				success : function(data){
					vue.queryBtn = false;
					if(data.ok){
						var result = data.data;
						vue.totalSize = result.totalElements;
						vue.tableData = result.content;
						
					}else{
						swal('查询失败:'+data.msg,'','error');
					}
				},
				error : function(data){
					this.queryBtn = false;
					swal('查询失败','','error');
				}
				
			});
			
		},
		onQueryForBtn() {
			
			this.queryBtn = true;
			var locationId = this.goodsLocation.id;
			
			if(locationId == null || locationId == ''){
				this.queryBtn = false;
				return;
			}
			
			$.ajax({
				
				url : COMMON_URL.URL + 'goodsLocationController/showLocationsGoods',
				dataType : 'json',
				type : 'get',
				data : {
					'locationId' : locationId,
					'pageNum' : vue.currentPage,
					'pageSize' : vue.pageSize
				},
				success : function(data){
					vue.queryBtn = false;
					if(data.ok){
						var result = data.data;
						vue.totalSize = result.totalElements;
						vue.tableData = result.content;
						
					}else{
						swal('查询失败:'+data.msg,'','error');
					}
				},
				error : function(data){
					this.queryBtn = false;
					swal('查询失败','','error');
				}
				
			});
		},
		initGoodLocation(){
			
			$.ajax({
				url : COMMON_URL.URL + 'goodsLocationController/getGoodLocation',
				dataType : 'json',
				type : 'get',
				success : function(data){
					if(data.ok){
						vue.locations = data.data;
					}else{
						swal(data.msg,'','warning');
					}
				},
				error : function(data){
					swal('查询库位失败','','error');
				}
			});
			
		}
	}
	
});